#!/bin/bash

if [ ! $# -eq 2 ] || [ -e "$2" ] && [ ! -d "$2" ]
then
    echo "usage: my_dircopy dir1 dir2"
    exit 1
elif [ ! -d "$1" ]
then
    echo "无法访问文件 '$1': No such file or directory"
    exit 1
elif [ ! -e "$2" ] 
then
    mkdir $2
fi

src_dir=$(readlink -f "$1")
dest_dir=$(readlink -f "$2")
file_list=$(ls "$src_dir")

for file in $file_list
do
    src_file="${src_dir}/${file}"
    if [ ! -d "$src_file" ]
    then
        cp -v "$src_file" "$dest_dir"
    fi
done